/*
 * SRM 209 Div 1 Prob 1
 */

import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;

class Country implements Comparable {
    String country;
    int[] s;
    
    public Country (String country) {
	this.country = country;
	s = new int[3];
    }
    
    public int compareTo (Object o) {
	Country first = this, second = (Country)o;
	for (int i = 0; i < 3; ++i)
	    if (first.s[i] != second.s[i])
		return second.s[i] - first.s[i];
	return first.country.compareTo (second.country);
    }
}

public class MedalTable
{
    public String[] generate(String[] results)
    {
	HashMap<String, Country> ts = new HashMap<String, Country> ();
	for (String str:results) {
	    String[] tmp = str.split ("\\s+");
	    for (int i = 0; i < 3; ++i) {
		String s = tmp[i];
		Country count = null;
		if (!ts.containsKey (s))
		    count = new Country (s);
		else
		    count = ts.get (s);
		count.s[i]++;
		ts.put (s, count);
	    }
	}
	ArrayList<Country> al = new ArrayList<Country> ();
	for (String s:ts.keySet ())
	    al.add (ts.get (s));
	Collections.sort (al);
	String[] ans = new String[al.size ()];
	for (int i = 0; i < al.size (); ++i) {
	    Country t2 = al.get (i);
	    ans[i] = t2.country + " " + t2.s[0] + " " + t2.s[1] + " " + t2.s[2];
	}
	return ans;
    }
    

}
//Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!